import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lib_database/lib_database.dart';
import 'package:lib_util/log/log.dart';

import '../../../module_common/bridge/native_channel_bridge.dart';
import '../provider/dapp_cache_provider.dart';
import '../widgets/hover_status.dart';
import 'package:provider/provider.dart';

class DAppHistoryUtil {
  static addCacheInfo(BuildContext context, {required DAppBean item}) async {
    // Log.logger.e('添加历史缓存:' + item.toString());
    final isExisted = await Provider.of<DAppCacheProvider>(context, listen: false).isCacheDAppExisted(item);
    if (!isExisted) {
      await Provider.of<DAppCacheProvider>(context, listen: false).addCache(item);
    }
  }

  static setConfirmBottomDialog(
    BuildContext context, {
    title = '',
    void Function()? onConfirm,
    void Function()? onCancel,
  }) {
    return showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        isScrollControlled: true,
        builder: (_) {
          return Container(
            height: 160.w,
            width: double.infinity,
            decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(20.w)),
            child: Column(
              children: [
                Container(
                    width: double.infinity,
                    height: 50.w,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: Colors.white,
                        // border: Border(
                        //   bottom: BorderSide(
                        //     color: Color.fromRGBO(243, 242, 247, 1),
                        //     width: 1,
                        //   ),
                        // ),
                        borderRadius:
                            BorderRadius.only(topLeft: Radius.circular(20.w), topRight: Radius.circular(20.w))),
                    child: Text(
                      title,
                      style: TextStyle(
                        fontSize: 14.sp,
                        color: Color.fromRGBO(134, 131, 145, 1),
                        fontWeight: FontWeight.w400,
                        height: 20.w / 14.w,
                      ),
                    )),
                HoverStatus(
                  defaultColor: Color.fromRGBO(255, 255, 255, 1),
                  hoverColor: Color.fromRGBO(246, 246, 246, 1),
                  onPressed: () {
                    onConfirm!();
                    Navigator.pop(context);
                  },
                  child: Container(
                    height: 54.w,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      border: Border(
                        top: BorderSide(
                          color: Color.fromRGBO(243, 242, 247, 1),
                          width: 1.w,
                        ),
                        bottom: BorderSide(
                          color: Color.fromRGBO(243, 242, 247, 1),
                          width: 4.w,
                        ),
                      ),
                    ),
                    child: Text('Confirm',
                        style: TextStyle(
                          fontSize: 16.sp,
                          color: Color.fromRGBO(255, 81, 0, 1),
                          fontWeight: FontWeight.w400,
                          height: 22.w / 16.w,
                        )),
                  ),
                ),
                HoverStatus(
                  defaultColor: Color.fromRGBO(255, 255, 255, 1),
                  hoverColor: Color.fromRGBO(246, 246, 246, 1),
                  onPressed: () {
                    if (onCancel != null) {
                      onCancel();
                    }
                    Navigator.pop(context);
                  },
                  child: Container(
                    height: 50.w,
                    alignment: Alignment.center,
                    child: Text('Cancel',
                        style: TextStyle(
                          color: Color.fromRGBO(134, 131, 145, 1),
                          fontWeight: FontWeight.w400,
                          fontSize: 16.sp,
                          height: 22.w / 16.w,
                        )),
                  ),
                )
              ],
            ),
          );
        });
  }
}
